package com.xiaoma.myaudience.biz.task;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.NameValuePair;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

import android.content.Context;

import com.xiaoma.myaudience.biz.model.NeteasePostFeedBackInfo;
import com.xiaoma.myaudience.biz.util.Constant;
import com.xiaoma.myaudience.util.HttpUtils;
import com.xiaoma.myaudience.util.Logger;
import com.xiaoma.myaudience.util.http.AndroidHttpClient;
import com.xiaoma.myaudience.util.model.ModelUtils;
import com.xiaoma.myaudience.util.task.BaseDataAsyncTask;

/**
 * 提交反馈
 * @author xali
 *
 */
public class PostFeedBackTask extends BaseDataAsyncTask<NeteasePostFeedBackInfo, Void, Map<String,Object>> {
    private final static String TAG = "PostFeedBackTask";

    /**
     * {@inheritDoc}
     * 
     * @param context
     * @param taskType
     * @param callback
     */
    public PostFeedBackTask(Context context, int taskType, DataAsyncCallback callback) {
        super(context, taskType, callback);
    }
    
    @Override
    protected Map<String,Object> doInBackground(NeteasePostFeedBackInfo... params) {
    	Map<String,Object> result = null;
    	if(params[0] == null) return result;
    	
    	NeteasePostFeedBackInfo info = params[0];
    	
    	String url = Constant.URL_FEEDBACK_PATH;
        Logger.i("url is "+url);
        try {
        	AndroidHttpClient client =getHttpClient();
        	//Context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);op:opinion
        	List<NameValuePair> l = new ArrayList<NameValuePair>();
        	l.add(new BasicNameValuePair("op", "opinion"));
        	l.add(new BasicNameValuePair("content", info.mMessage));
			JSONObject jsonobj = HttpUtils.getHttpJSONObjectResult(getHttpClient(), url, l, HttpUtils.POST);
			if(jsonobj!=null){
				String obj = jsonobj.getString("code");
				if(obj!=null) {
					result = new HashMap<String, Object>();
					result.put("code", obj);
				}
					
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
       
        return result;
    }
    
}
